/* GUI CONVERTED from rqavmt.p (converter v1.76) Thu Oct 25 04:03:32 2001 */
/* rqavmt.p - Vertical Approver Maintenance                                 */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.             */
/* $Revision: 1.3.1.3 $                                                             */
/*V8:ConvertMode=Maintenance                                                */
/* REVISION 8.5       LAST MODIFIED: 04/15/97  BY: *J1Q2* Patrick Rowan     */
/* REVISION 8.6       LAST MODIFIED: 05/20/98  BY: *K1Q4* Alfred Tan        */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00  BY: *N08T* Annasaheb Rahane  */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00  BY: *N0KP* myb               */
/* Old ECO marker removed, but no ECO header exists *F0PN*                  */
/* $Revision: 1.3.1.3 $       BY: Manisha Sawant       DATE: 10/21/01  ECO: *N14P*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/*!
 ----------------------------------------------------------------------------
 DESCRIPTION: ADDS/MODS/DELETES vertical requisition approvers.
              Supports the multi-line Purchase Requisition Module of MFG/PRO.

 Notes:
 1) Sub-Account From and Sub-Account To are optional entries.
    If Sub-Account From = "" or Sub-Account To = "", this implies an
    open-ended range; meaning that the approver will be selected for
    any requisitions in the range.
 2) Cost Center From and Cost Center To are optional entries and imply
    open-ended ranges.  They follow the same logic as Sub-Account above.
 3) Start and End Effectivity dates are optional entries and imply open-ended
    ranges.  If both dates are entered they are validated to ensure they
    are in range.
 ============================================================================
!*/

/* DISPLAY TITLE  */
{mfdtitle.i "b+ "}

/* CONSTANTS */
{rqconst.i}

/* VARIABLES */
{rqavars.i}
define variable start_date            like rqa_start no-undo.
define variable end_date              like rqa_end no-undo.

/* LOGICALS  */
define variable del-yn                like mfc_logical no-undo
   initial no.

/* FRAME A: SELECTION FORM   */

/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
rqa_apr               colon 25
   var_apr_name             at 37  no-label
   rqa_entity            colon 25
   var_entity_name          at 37  no-label
   rqa_sub_from          colon 25
   var_sub_from_desc        at 37  no-label
   rqa_cc_from           colon 25
   var_cc_from_desc         at 37  no-label
   rqa_start             colon 25
   rqa_end               colon 50
   skip(1)
   rqa_sub_to            colon 25
   var_sub_to_desc          at 37  no-label
   rqa_cc_to             colon 25
   var_cc_to_desc           at 37  no-label
   rqa_rvw_level         colon 25
   var_rvw_level_amt     colon 37
   rqa_rvw_req           colon 72
   rqa_apr_level         colon 25
   var_apr_level_amt     colon 37
   rqa_apr_req           colon 72
   rqa_alt_apr[1]        colon 25
   var_alt1_apr_name        at 37  no-label
   rqa_alt_apr[2]        colon 25
   var_alt2_apr_name        at 37  no-label
   rqa_admin_apr         colon 25
   var_admin_apr_name       at 37  no-label
   start_date            colon 25
   end_date              colon 25
 SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

/* DISPLAY */
view frame a.

/* SET APPROVER TYPE */
var_apr_type = vertical.

mainloop:
repeat with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.


   /* PROMPT-FOR KEYS */

   prompt-for
      rqa_apr
      rqa_entity
      rqa_sub_from
      rqa_cc_from
      rqa_start
      with frame a
   editing:

      /* FIND NEXT/PREVIOUS RECORD */

      {mfnp08.i rqa_mstr rqa_type_apr
         " rqa_type = var_apr_type "
         rqa_apr "input rqa_apr"
         rqa_entity "input rqa_entity"
         rqa_sub_from "input rqa_sub_from"}

      if recno <> ?
      then do:
         display
            rqa_apr
            rqa_entity
            rqa_sub_from
            rqa_cc_from
            rqa_sub_to
            rqa_cc_to
            rqa_rvw_level
            rqa_rvw_req
            rqa_apr_level
            rqa_apr_req
            rqa_alt_apr[1]
            rqa_alt_apr[2]
            rqa_admin_apr
            rqa_start
            rqa_end
            rqa_start @ start_date
            rqa_end @ end_date
         with frame a.

         /*  RETRIEVE NAMES/DESCRIPTIONS  */
         {rqadesc.i}

         display
            var_apr_name
            var_entity_name
            var_sub_from_desc
            var_cc_from_desc
            var_sub_to_desc
            var_cc_to_desc
            var_rvw_level_amt
            var_apr_level_amt
            var_alt1_apr_name
            var_alt2_apr_name
            var_admin_apr_name
         with frame a.

      end.  /* if recno <> ? */

   end.  /* prompt-for */

   /*  ADD/MODIFY/DELETE  */
   find rqa_mstr where
      rqa_apr         = input rqa_apr      and
      rqa_type        = var_apr_type       and
      rqa_entity      = input rqa_entity   and
      rqa_category    = ""                 and
      rqa_job         = ""                 and
      rqa_site        = ""                 and
      rqa_prod_line   = ""                 and
      rqa_sub_from    = input rqa_sub_from and
      rqa_cc_from     = input rqa_cc_from  and
      rqa_start       = input rqa_start
   exclusive-lock
      no-error.

   if not available rqa_mstr
   then do:

      /* INITIALIZE VALIDATION VARIABLES  */
      assign
         var_apr         = input rqa_apr
         var_entity      = input rqa_entity
         var_category    = ""
         var_job         = ""
         var_site        = ""
         var_prod_line   = "".

      /* VALIDATE KEYS  */
      {rqaval1.i}

      /* APPROVER ID */
      if not valid_apr
      then do:
         /* USER ID DOES NOT EXIST */
         {pxmsg.i &MSGNUM=5605 &ERRORLEVEL=3}
         next-prompt rqa_apr.
         undo, retry.
      end.

      /* ENTITY */
      if not valid_entity
      then do:
         /* INVALID ENTITY */
         {pxmsg.i &MSGNUM=3061 &ERRORLEVEL=3}
         next-prompt rqa_entity.
         undo, retry.
      end.

      /* ADD NEW RECORD */
      {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}
      create rqa_mstr.
      assign
         rqa_apr
         rqa_type     = var_apr_type
         rqa_sub_from
         rqa_cc_from
         rqa_start
         rqa_entity
         rqa_sub_to   = input rqa_sub_from
         rqa_cc_to    = input rqa_cc_from
         rqa_rvw_req  = no
         rqa_apr_req  = no.

      if recid(rqa_mstr) = -1
      then .

   end.  /* if not available rqa_mstr */

   var_recid = recid(rqa_mstr).

   display
      rqa_apr
      rqa_entity
      rqa_sub_from
      rqa_cc_from
      rqa_sub_to
      rqa_cc_to
      rqa_rvw_level
      rqa_rvw_req
      rqa_apr_level
      rqa_apr_req
      rqa_alt_apr[1]
      rqa_alt_apr[2]
      rqa_admin_apr
      rqa_start
      rqa_end
      rqa_start @ start_date
      rqa_end @ end_date
   with frame a.

   /*  RETRIEVE NAMES/DESCRIPTIONS  */
   {rqadesc.i}

   display
      var_apr_name
      var_entity_name
      var_sub_from_desc
      var_cc_from_desc
      var_sub_to_desc
      var_cc_to_desc
      var_rvw_level_amt
      var_apr_level_amt
      var_alt1_apr_name
      var_alt2_apr_name
      var_admin_apr_name
   with frame a.

   ststatus = stline[2].
   status input ststatus.

   assign
      del-yn = no
      start_date = rqa_start
      end_date   = rqa_end.

   setloop1:
   do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

      set
         rqa_sub_to
         rqa_cc_to
         rqa_rvw_level
         rqa_rvw_req
         rqa_apr_level
         rqa_apr_req
         rqa_alt_apr[1]
         rqa_alt_apr[2]
         rqa_admin_apr
         start_date
         end_date
         go-on("F5" "CTRL-D")
      with frame a.

      /*  RETRIEVE NAMES/DESCRIPTIONS  */
      {rqadesc.i}

      display
         var_sub_to_desc
         var_cc_to_desc
         var_rvw_level_amt
         var_apr_level_amt
         var_alt1_apr_name
         var_alt2_apr_name
         var_admin_apr_name
      with frame a.

      /*  DELETE  */
      if lastkey = keycode("F5") or lastkey = keycode("CTRL-D")
      then do:
         del-yn = yes.
         /* CONFIRM DELETE */
         {pxmsg.i &MSGNUM=11 &ERRORLEVEL=1 &CONFIRM=del-yn}
         if del-yn = no
         then
            undo setloop1.
      end.  /* if lastkey = keycode("F5") */

      if del-yn
      then do:
         /* OK TO DELETE */
         delete rqa_mstr.
         clear frame a.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
         del-yn = no.
         next mainloop.
      end.  /* if del-yn */

      /* VALIDATE DATA */
      {rqaval2.i}

      /* SUB ACCOUNT RANGE CHECK */
      if not valid_sub_range
      then do:
         /* INVALID RANGE */
         {pxmsg.i &MSGNUM=6905 &ERRORLEVEL=3}
         next-prompt rqa_sub_to.
         undo, retry.
      end.

      /* COST CENTER RANGE CHECK */
      if not valid_cc_range
      then do:
         /* INVALID RANGE */
         {pxmsg.i &MSGNUM=6905 &ERRORLEVEL=3}
         next-prompt rqa_cc_to.
         undo, retry.
      end.

      /* REVIEW LEVEL */
      if not valid_rvw_level
      then do:
         /* INVALID LEVEL CODE */
         {pxmsg.i &MSGNUM=2058 &ERRORLEVEL=3}
         next-prompt rqa_rvw_level.
         undo, retry.
      end.

      /* APPROVAL LEVEL */
      if not valid_apr_level
      then do:
         /* INVALID LEVEL CODE */
         {pxmsg.i &MSGNUM=2058 &ERRORLEVEL=3}
         next-prompt rqa_apr_level.
         undo, retry.
      end.

      /* ALTERNATE APPROVER #1 */
      if not valid_alt1_apr
      then do:
         /* USER ID DOES NOT EXIST */
         {pxmsg.i &MSGNUM=5605 &ERRORLEVEL=3}
         next-prompt rqa_alt_apr[1].
         undo, retry.
      end.

      if not active_alt1_apr
      then do:
         /* ALTERNATE MUST BE ACTIVE OR FUTURE */
         {pxmsg.i &MSGNUM=1845 &ERRORLEVEL=3}
         next-prompt rqa_alt_apr[1].
         undo, retry.
      end.

      if not valid_alt1_level
      then do:
         /* ALTERNATE MUST HAVE A MINIMUM APPROVAL LEVEL OF */
         {pxmsg.i &MSGNUM=1846 &ERRORLEVEL=3 &MSGARG1=rqa_apr_level}
         next-prompt rqa_alt_apr[1].
         undo, retry.
      end.

      /* ALTERNATE APPROVER #2 */
      if not valid_alt2_apr
      then do:
         /* USER ID DOES NOT EXIST */
         {pxmsg.i &MSGNUM=5605 &ERRORLEVEL=3}
         next-prompt rqa_alt_apr[2].
         undo, retry.
      end.

      if not active_alt2_apr
      then do:
         /* ALTERNATE MUST BE ACTIVE OR FUTURE */
         {pxmsg.i &MSGNUM=1845 &ERRORLEVEL=3}
         next-prompt rqa_alt_apr[2].
         undo, retry.
      end.

      if not valid_alt2_level
      then do:
         /* ALTERNATE MUST HAVE A MINIMUM APPROVAL LEVEL OF */
         {pxmsg.i &MSGNUM=1846 &ERRORLEVEL=3 &MSGARG1=rqa_apr_level}
         next-prompt rqa_alt_apr[2].
         undo, retry.
      end.

      /* ADMIN APPROVER */
      if not valid_admin_apr
      then do:
         /* USER ID DOES NOT EXIST */
         {pxmsg.i &MSGNUM=5605 &ERRORLEVEL=3}
         next-prompt rqa_admin_apr.
         undo, retry.
      end.

      /* DATE RANGE CHECK */
      if not valid_date_range
      then do:
         /* END DATE CANNOT BE BEFORE START DATE */
         {pxmsg.i &MSGNUM=123 &ERRORLEVEL=3}
         next-prompt end_date.
         undo, retry.
      end.

      /* DATE OVERLAP CHECK */
      if overlap_start_date
      then do:
         /* CONFLICTS WITH AN EXISTING RANGE */
         {pxmsg.i &MSGNUM=1547 &ERRORLEVEL=3}
         next-prompt start_date.
         undo, retry.
      end.

      /* DATE OVERLAP CHECK */
      if overlap_end_date
      then do:
         /* CONFLICTS WITH AN EXISTING RANGE */
         {pxmsg.i &MSGNUM=1547 &ERRORLEVEL=3}
         next-prompt end_date.
         undo, retry.
      end.

      /* E-MAIL CHECK */
      if email_active
      then do:

         /* APPROVER E-MAIL */
         if not apr_email_found
         then do:
            /* E-MAIL ADDRESS DOES NOT EXIST */
            {pxmsg.i &MSGNUM=1777 &ERRORLEVEL=2 &MSGARG1=rqa_apr}
         end.

         /* ALTERNATE APPROVER #1 E-MAIL */
         if not alt1_email_found
         then do:
            /* E-MAIL ADDRESS DOES NOT EXIST */
            {pxmsg.i &MSGNUM=1777 &ERRORLEVEL=2 &MSGARG1=rqa_alt_apr[1]}
         end.

         /* ALTERNATE APPROVER #2 E-MAIL */
         if not alt2_email_found
         then do:
            /* E-MAIL ADDRESS DOES NOT EXIST */
            {pxmsg.i &MSGNUM=1777 &ERRORLEVEL=2 &MSGARG1=rqa_alt_apr[2]}
         end.

         /* ADMIN APPROVER E-MAIL */
         if not admin_email_found
         then do:
            /* E-MAIL ADDRESS DOES NOT EXIST */
            {pxmsg.i &MSGNUM=1777 &ERRORLEVEL=2 &MSGARG1=rqa_admin_apr}
         end.

      end.  /* if email-active */

      /* SET DEFAULT TO "NO" */
      if input rqa_rvw_level = ""
      then
         rqa_rvw_req = no.

      if input rqa_apr_level = ""
      then
         rqa_apr_req = no.

      /* REFLECT DATE CHANGES IN KEY SECTION */
      assign
         rqa_start = start_date
         rqa_end   = end_date.

      display
         rqa_rvw_req
         rqa_apr_req
         rqa_start
         rqa_end
      with frame a.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* setloop1  */

end.
/*GUI*/ if global-beam-me-up then undo, leave.
  /* mainloop repeat  */

status input.
